
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  <title>IOS项目脚本自动化批量打包并上传第三方平台 | 向🐑</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="description" content="在公司项目中O单批量化打包替换项目的产品部分属性">
<meta property="og:type" content="article">
<meta property="og:title" content="IOS项目脚本自动化批量打包并上传第三方平台">
<meta property="og:url" content="https://kziwws.github.io/2023/01/21/technology20230121151206/index.html">
<meta property="og:site_name" content="向🐑">
<meta property="og:description" content="在公司项目中O单批量化打包替换项目的产品部分属性">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://s1.ax1x.com/2023/02/27/pp97uJs.png">
<meta property="og:image" content="https://s1.ax1x.com/2023/02/27/pp9bZCj.md.png">
<meta property="og:image" content="https://s1.ax1x.com/2023/02/27/ppCpfpT.png">
<meta property="og:image" content="https://s1.ax1x.com/2023/02/27/pp9qYTS.png">
<meta property="og:image" content="https://s1.ax1x.com/2023/02/27/pp9q2Y4.png">
<meta property="og:image" content="https://s1.ax1x.com/2023/02/27/pp9Lp0f.png">
<meta property="article:published_time" content="2023-01-21T07:12:06.000Z">
<meta property="article:modified_time" content="2024-06-03T06:38:47.000Z">
<meta property="article:author" content="kziwws">
<meta property="article:tag" content="IOS项目脚本自动化批量打包并上传第三方平台">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://s1.ax1x.com/2023/02/27/pp97uJs.png">
  
    <link rel="alternative" href="/atom.xml" title="向🐑" type="application/atom+xml">
  
  
    <link rel="icon" href="/favicon.png">
  
  
<link rel="stylesheet" href="/css/style.css">

  <!--[if lt IE 9]><script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7/html5shiv.min.js"></script><![endif]-->
  <!--  -->
  
<script>
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?51e08434b847b38641d02f11be4eb143";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script>


<meta name="generator" content="Hexo 4.2.1"></head>
<body>
<div id="container">
  <div id="wrap">
    <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/" id="logo">向🐑</a>
      </h1>
      
        <h2 id="subtitle-wrap">
          <a href="/" id="subtitle">一只站在树上的鸟，从来不害怕树枝突然折断，因为它相信的不是树枝，而是它自己的翅膀！</a>
        </h2>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="/">首页</a>
        
          <a class="main-nav-link" href="/tags/technology">编程技术</a>
        
          <a class="main-nav-link" href="/tags/poetry">诗</a>
        
          <a class="main-nav-link" href="/tags/life">生活随笔</a>
        
          <a class="main-nav-link" href="/archives">所有文章</a>
        
      </nav>
      <nav id="sub-nav">
        
          <a id="nav-rss-link" class="nav-icon" href="/atom.xml" title="RSS Feed"></a>
        
        
        
        <a href="javascript:;" class="popup-trigger nav-icon" id="nav-search-btn"></a>
        
      </nav>
      <div id="search-form-wrap">
        <form action="//www.baidu.com/baidu" method="get" accept-charset="utf-8" class="search-form">
          <input type="search" name="word" maxlength="20" class="search-form-input" placeholder="Search">
          <input type="submit" value="" class="search-form-submit">
          <input name=tn type=hidden value="bds">
          <input name=cl type=hidden value="3">
          <input name=ct type=hidden value="2097152">
          <input type="hidden" name="si" value="kziwws.github.io">
        </form>
      </div>
    </div>
  </div>
  <div class="local-search-inner"><div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <span id="icon-search"></span>
    </span>
    <span class="popup-btn-close">
      <span id="icon-close"></span>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off"
             placeholder="本地搜索..." spellcheck="false"
             type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div></div>
</header>



    <div class="outer">
      <section id="main"><article id="post-technology20230121151206" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2023/01/21/technology20230121151206/" class="article-date">
  <time datetime="2023-01-21T07:12:06.000Z" itemprop="datePublished">2023-01-21</time>
</a>
    
  <div class="article-category">
    <a class="article-category-link" href="/categories/ios/">ios</a>
  </div>

  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="article-title" itemprop="name">
      IOS项目脚本自动化批量打包并上传第三方平台
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h5 id="由于公司项目需求然后想要一个项目打包多个包，然后app名字、bundleId、服务器连接URL、appIocn、app项目内容渠道参数不一样，针对网上看了一些教程和方式，现在总结一下。"><a href="#由于公司项目需求然后想要一个项目打包多个包，然后app名字、bundleId、服务器连接URL、appIocn、app项目内容渠道参数不一样，针对网上看了一些教程和方式，现在总结一下。" class="headerlink" title="由于公司项目需求然后想要一个项目打包多个包，然后app名字、bundleId、服务器连接URL、appIocn、app项目内容渠道参数不一样，针对网上看了一些教程和方式，现在总结一下。"></a>由于公司项目需求然后想要一个项目打包多个包，然后app名字、bundleId、服务器连接URL、appIocn、app项目内容渠道参数不一样，针对网上看了一些教程和方式，现在总结一下。</h5><p>如果想要知道单个项目脚本打包请查看<a href="https://kziwws.github.io/2023/01/20/technology20230120161001/">IOS脚本单独打包</a></p>
<h5 id="一、bash脚本"><a href="#一、bash脚本" class="headerlink" title="一、bash脚本"></a><strong>一、bash脚本</strong></h5><p>bash 是一个用 C 语言编写的程序，它是用户使用 Linux 的桥梁。bash 既是一种命令语言，又是一种程序设计语言。<a href="https://www.runoob.com/linux/linux-bash.html" target="_blank" rel="noopener">bash脚本基础学习</a></p>
<p><strong>项目目录结构</strong></p>
<p><a href="https://imgse.com/i/pp97uJs" target="_blank" rel="noopener"><img src="https://s1.ax1x.com/2023/02/27/pp97uJs.png" alt="pp97uJs.png"></a></p>
<p><strong>结构说明：</strong></p>
<p>MutaPackageScript.sh : 为脚本文件 (批量时部分配置修改)</p>
<p>Plist：为打包4种打包模式 AdHoc、AppStore、Development、Enterprise （不需要动）</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;?xml version="1.0" encoding="UTF-8"?&gt;</span></span><br><span class="line"><span class="meta">&lt;!DOCTYPE <span class="meta-keyword">plist</span> <span class="meta-keyword">PUBLIC</span> <span class="meta-string">"-//Apple//DTD PLIST 1.0//EN"</span> <span class="meta-string">"http://www.apple.com/DTDs/PropertyList-1.0.dtd"</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">plist</span> <span class="attr">version</span>=<span class="string">"1.0"</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">dict</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">key</span>&gt;</span>method<span class="tag">&lt;/<span class="name">key</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">string</span>&gt;</span>development<span class="tag">&lt;/<span class="name">string</span>&gt;</span>//这儿development、enterprise、ad-hoc、app-store四种</span><br><span class="line">	<span class="tag">&lt;<span class="name">key</span>&gt;</span>signingStyle<span class="tag">&lt;/<span class="name">key</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">string</span>&gt;</span>automatic<span class="tag">&lt;/<span class="name">string</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">key</span>&gt;</span>compileBitcode<span class="tag">&lt;/<span class="name">key</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">false</span>/&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dict</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">plist</span>&gt;</span></span><br></pre></td></tr></table></figure>

<a id="more"></a>

<p>AppIcon: 为要打包的替换的AppIcon图系列，这儿首先要用工具生成好所有图，名字必须是AppIcon~系列的，原因是同一个包脚本会替换覆盖操作。我是使用的一个Asset Catalog Creator 你自己使用其他的也行，能生成就行。(需要使用工具生成)</p>
<p><a href="https://imgse.com/i/pp9bZCj" target="_blank" rel="noopener"><img src="https://s1.ax1x.com/2023/02/27/pp9bZCj.md.png" alt="pp9bZCj.md.png"></a></p>
<p>目录子目录文件夹就是当打包多个的时候AppIcon文件目录，名字对应的脚本文件的里的配置文件appIconArr参数的名字，修改app文件配置参数，所以如果新增APP时请修改新增此脚本参数，不然会找不到APPIcon文件图片替换目录。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">appIconArr=(</span><br><span class="line">   <span class="string">"yqb_AppIcon"</span></span><br><span class="line">   <span class="string">"lebzs_AppIcon"</span></span><br><span class="line">)</span><br></pre></td></tr></table></figure>

<p>这儿启动图和引导图都可以放在这个里面，然后会同一替换，主要图片名字记得保持一致，例如在项目中启动图叫</p>
<p>launch_s.png，重新打包的时候也请命名为launch_s.png放在AppIcon文件夹包里。</p>
<p><a href="https://imgse.com/i/ppCpfpT" target="_blank" rel="noopener"><img src="https://s1.ax1x.com/2023/02/27/ppCpfpT.png" alt="ppCpfpT.png"></a></p>
<p><strong>二、开始打包操作</strong></p>
<ul>
<li>操作脚本</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">cd</span> /Users/mac/Desktop/您的项目名称/MutaPackageScript</span><br><span class="line">sh MutaPackageScript.sh</span><br></pre></td></tr></table></figure>

<p>上面要cd到当前项目文件夹下的MutaPackageScript脚本目录，原因是为了当其他项目在不同的目录路径下时，获取到项目层级会不一致，不同的电脑上可能不是同一个，所以cd项目时需要先项目目录文件下MutaPackageScript目录下。</p>
<p>所有脚本如下：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br><span class="line">214</span><br><span class="line">215</span><br><span class="line">216</span><br><span class="line">217</span><br><span class="line">218</span><br><span class="line">219</span><br><span class="line">220</span><br><span class="line">221</span><br><span class="line">222</span><br><span class="line">223</span><br><span class="line">224</span><br><span class="line">225</span><br><span class="line">226</span><br><span class="line">227</span><br><span class="line">228</span><br><span class="line">229</span><br><span class="line">230</span><br><span class="line">231</span><br><span class="line">232</span><br><span class="line">233</span><br><span class="line">234</span><br><span class="line">235</span><br><span class="line">236</span><br><span class="line">237</span><br><span class="line">238</span><br><span class="line">239</span><br><span class="line">240</span><br><span class="line">241</span><br><span class="line">242</span><br><span class="line">243</span><br><span class="line">244</span><br><span class="line">245</span><br><span class="line">246</span><br><span class="line">247</span><br><span class="line">248</span><br><span class="line">249</span><br><span class="line">250</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#!/bin/bash</span></span><br><span class="line"></span><br><span class="line">#  Script.sh</span><br><span class="line">#  Package</span><br><span class="line">#  Created by wws on 2023/02/25.</span><br><span class="line">#  Copyright © 2023 年 wws. All rights reserved.</span><br><span class="line"></span><br><span class="line"># 1.Configuration Info</span><br><span class="line"></span><br><span class="line"># 是否编译工作空间 (例:若是用Cocopods管理的.xcworkspace项目,赋值true;用Xcode默认创建的.xcodeproj,赋值false)</span><br><span class="line">is_workspace=<span class="string">"true"</span></span><br><span class="line"># 指定要打包编译的方式 : Release,Debug...</span><br><span class="line">build_configuration=<span class="string">"Release"</span></span><br><span class="line"></span><br><span class="line"># 返回上一级目录,进入项目工程目录</span><br><span class="line">cd ..</span><br><span class="line"># 获取项目名称</span><br><span class="line">projectName=<span class="string">`find . -name *.xcodeproj | awk -F "[/.]" '&#123;print $(NF-1)&#125;'`</span></span><br><span class="line"># Scheme Name</span><br><span class="line">schemeName=$&#123;projectName&#125;</span><br><span class="line">#cd ~/Desktop/$&#123;schemeName&#125;</span><br><span class="line"># 图标路径</span><br><span class="line">iconPath=<span class="string">"./MutaPackageScript/AppIcon"</span></span><br><span class="line"># 打包所有生成路径</span><br><span class="line">ipaPath=~<span class="regexp">/Desktop/</span>IPAS</span><br><span class="line"># 临时生成APP路径</span><br><span class="line">buildDir=<span class="string">"$&#123;ipaPath&#125;/build/$&#123;schemeName&#125;.xcarchive"</span></span><br><span class="line"></span><br><span class="line">plistPath=<span class="string">"./MutaPackageScript/Plist"</span></span><br><span class="line"># 导出ipa所需要的plist文件路径 (默认为AdHocExportOptionsPlist.plist)</span><br><span class="line">exportOptionsPlistPath=<span class="string">"$&#123;plistPath&#125;/AdHocExportOptionsPlist.plist"</span></span><br><span class="line"></span><br><span class="line">#app名字</span><br><span class="line">displayNameArr=(</span><br><span class="line">    <span class="string">"app1的名字"</span></span><br><span class="line">    <span class="string">"app2的名字"</span></span><br><span class="line">)</span><br><span class="line">#app的bundleId</span><br><span class="line">bundleIdentifierArr=(</span><br><span class="line">    <span class="string">"com.qyf.qyf"</span></span><br><span class="line">    <span class="string">"com.qyf.ysf"</span></span><br><span class="line">)</span><br><span class="line">#获取URL链接的主机地址编号</span><br><span class="line">hostNumberArr=(</span><br><span class="line">    <span class="string">"A022"</span></span><br><span class="line">    <span class="string">"A021"</span></span><br><span class="line">)</span><br><span class="line">#修改app文件地址</span><br><span class="line">appIconArr=(</span><br><span class="line">    <span class="string">"yqb_AppIcon"</span></span><br><span class="line">    <span class="string">"lebzs_AppIcon"</span></span><br><span class="line">)</span><br><span class="line">#打包渠道号</span><br><span class="line">channelCodeArr=(</span><br><span class="line">    <span class="string">"112"</span></span><br><span class="line">    <span class="string">"115"</span></span><br><span class="line">)</span><br><span class="line">#版本号</span><br><span class="line">versionArr=(</span><br><span class="line">    <span class="string">"1.0.3"</span></span><br><span class="line">    <span class="string">"1.0.4"</span></span><br><span class="line">)</span><br><span class="line">#服务器默认连接的地址</span><br><span class="line">serverArr=(</span><br><span class="line">    <span class="string">"https://www.xxx.com/app1/"</span></span><br><span class="line">    <span class="string">"https://www.xxx.com/app2/"</span></span><br><span class="line">)</span><br><span class="line"></span><br><span class="line"># 开始时间</span><br><span class="line">beginTime=<span class="string">`date +%s`</span></span><br><span class="line"></span><br><span class="line"># 清除缓存</span><br><span class="line">rm -rf mkdir $&#123;ipaPath&#125;</span><br><span class="line"># 创建打包目录</span><br><span class="line">mkdir $&#123;ipaPath&#125;</span><br><span class="line"></span><br><span class="line"># 蒲公英分发参数 不分发可忽略 默认不分发 下面的两个KEY是默认测试的网址对应KEY 换成你自己的</span><br><span class="line">isUploadPgyer=<span class="number">0</span></span><br><span class="line">USERKEY=<span class="string">"xxx"</span></span><br><span class="line">APIKEY=<span class="string">"xxx"</span></span><br><span class="line"></span><br><span class="line"># fir分发参数 不分发可忽略 默认分发 Token换成你自己的</span><br><span class="line">isUploadFir=<span class="number">1</span></span><br><span class="line">FirApiToken=<span class="string">"931b41960fd413455496b9465ec910adb97"</span></span><br><span class="line"></span><br><span class="line"># AdHoc,AppStore,Enterprise,Development四种打包方式</span><br><span class="line"> echo <span class="string">"\033[36;1m请选择打包方式(输入序号,按回车即可) \033[0m"</span></span><br><span class="line"> echo <span class="string">"\033[33;1m1. AdHoc       \033[0m"</span></span><br><span class="line"> echo <span class="string">"\033[33;1m2. AppStore    \033[0m"</span></span><br><span class="line"> echo <span class="string">"\033[33;1m3. Enterprise  \033[0m"</span></span><br><span class="line"> echo <span class="string">"\033[33;1m4. Development \033[0m"</span></span><br><span class="line"> #读取用户输入并存到变量里</span><br><span class="line"> read parameter</span><br><span class="line"> sleep <span class="number">0.5</span></span><br><span class="line"> method=<span class="string">"$parameter"</span></span><br><span class="line"></span><br><span class="line"># 判读用户是否有输入</span><br><span class="line"><span class="keyword">if</span> [ -n <span class="string">"$method"</span> ]</span><br><span class="line">then</span><br><span class="line">    <span class="keyword">if</span> [ <span class="string">"$method"</span> = <span class="string">"1"</span> ] ; then</span><br><span class="line">    exportOptionsPlistPath=<span class="string">"$&#123;plistPath&#125;/AdHocExportOptionsPlist.plist"</span></span><br><span class="line">    elif [ <span class="string">"$method"</span> = <span class="string">"2"</span> ] ; then</span><br><span class="line">    exportOptionsPlistPath=<span class="string">"$&#123;plistPath&#125;/AppStoreExportOptionsPlist.plist"</span></span><br><span class="line">    elif [ <span class="string">"$method"</span> = <span class="string">"3"</span> ] ; then</span><br><span class="line">    exportOptionsPlistPath=<span class="string">"$&#123;plistPath&#125;/EnterpriseExportOptionsPlist.plist"</span></span><br><span class="line">    elif [ <span class="string">"$method"</span> = <span class="string">"4"</span> ] ; then</span><br><span class="line">    exportOptionsPlistPath=<span class="string">"$&#123;plistPath&#125;/DevelopmentExportOptionsPlist.plist"</span></span><br><span class="line">    <span class="keyword">else</span></span><br><span class="line">    echo <span class="string">"输入的参数无效!!!"</span></span><br><span class="line">    exit <span class="number">1</span></span><br><span class="line">    fi</span><br><span class="line">fi</span><br><span class="line"></span><br><span class="line">echo <span class="string">"\033[32m*************************  开始构建项目  *************************  \033[0m"</span></span><br><span class="line"></span><br><span class="line">path=<span class="string">"$&#123;ipaPath&#125;/build"</span></span><br><span class="line"># 删除临时旧的xcarchive文件和打包项目</span><br><span class="line">rm -rf mkdir $&#123;path&#125;</span><br><span class="line">mkdir $&#123;path&#125;</span><br><span class="line"></span><br><span class="line"># 指定输出文件目录不存在则创建</span><br><span class="line"><span class="keyword">if</span> [ -d <span class="string">"$path"</span> ] ; then</span><br><span class="line">echo $path</span><br><span class="line"><span class="keyword">else</span></span><br><span class="line">mkdir -pv $path</span><br><span class="line">fi</span><br><span class="line"></span><br><span class="line"># Build 生成 APPs</span><br><span class="line"># 判断编译的项目类型是workspace还是project</span><br><span class="line"><span class="keyword">if</span> $is_workspace ; then</span><br><span class="line"># 编译前清理工程</span><br><span class="line">xcodebuild clean -workspace $&#123;projectName&#125;.xcworkspace \</span><br><span class="line">                 -scheme $&#123;schemeName&#125; \</span><br><span class="line">                 -configuration $&#123;build_configuration&#125;</span><br><span class="line"></span><br><span class="line">xcodebuild archive -workspace $&#123;projectName&#125;.xcworkspace \</span><br><span class="line">                   -scheme $&#123;schemeName&#125; \</span><br><span class="line">                   -configuration $&#123;build_configuration&#125; \</span><br><span class="line">                   -archivePath $&#123;buildDir&#125;</span><br><span class="line"><span class="keyword">else</span></span><br><span class="line"># 编译前清理工程</span><br><span class="line">xcodebuild clean -project $&#123;projectName&#125;.xcodeproj \</span><br><span class="line">                 -scheme $&#123;schemeName&#125; \</span><br><span class="line">                 -configuration $&#123;build_configuration&#125;</span><br><span class="line"></span><br><span class="line">xcodebuild archive -project $&#123;projectName&#125;.xcodeproj \</span><br><span class="line">                   -scheme $&#123;schemeName&#125; \</span><br><span class="line">                   -configuration $&#123;build_configuration&#125; \</span><br><span class="line">                   -archivePath $&#123;buildDir&#125;</span><br><span class="line">fi</span><br><span class="line"></span><br><span class="line">#  检查是否构建成功</span><br><span class="line">#  xcarchive 实际是一个文件夹不是一个文件所以使用 -d 判断</span><br><span class="line"><span class="keyword">if</span> [ -d <span class="string">"$buildDir"</span> ] ; then</span><br><span class="line">echo <span class="string">"\033[32;1m项目构建成功  \033[0m"</span></span><br><span class="line"><span class="keyword">else</span></span><br><span class="line">echo <span class="string">"\033[31;1m项目构建失败  \033[0m"</span></span><br><span class="line">exit <span class="number">1</span></span><br><span class="line">fi</span><br><span class="line"></span><br><span class="line">appPackNum=$&#123;#displayNameArr[*]&#125;</span><br><span class="line"># ----全部打包----</span><br><span class="line"><span class="keyword">for</span> (( i=<span class="number">0</span>; i&lt;appPackNum; i++ )); <span class="keyword">do</span></span><br><span class="line">    # App DisPlay Name 打包名字</span><br><span class="line">    displayName=$&#123;displayNameArr[$&#123;i&#125;]&#125;</span><br><span class="line">    # App BundleIdentifier 打包标识ID</span><br><span class="line">    bundleIdentifier=$&#123;bundleIdentifierArr[$&#123;i&#125;]&#125;</span><br><span class="line">    # App Icon File Name 打包AppIocn文件路径</span><br><span class="line">    appIcon=$&#123;appIconArr[$&#123;i&#125;]&#125;</span><br><span class="line">    # App channelCode 打包渠道</span><br><span class="line">    channelCode=$&#123;channelCodeArr[$&#123;i&#125;]&#125;</span><br><span class="line">    # App hostNumber 请求的主机地址编号</span><br><span class="line">    hostNumber=$&#123;hostNumberArr[$&#123;i&#125;]&#125;</span><br><span class="line">    # App version 版本号</span><br><span class="line">    version=$&#123;versionArr[$&#123;i&#125;]&#125;</span><br><span class="line">    # App hostUrl 服务器地址</span><br><span class="line">    hostUrl=$&#123;serverArr[$&#123;i&#125;]&#125;</span><br><span class="line">    </span><br><span class="line">    # 创建不同 app ipa 目录</span><br><span class="line">    rm -rf $ipaPath/$&#123;displayName&#125;</span><br><span class="line">    mkdir $ipaPath/$&#123;displayName&#125;</span><br><span class="line">    </span><br><span class="line">    echo <span class="string">"33[31m appName:$displayName appIconName:$appIcon appChannelName:$channelCode bundleID:$bundleIdentifier n 33[0m"</span></span><br><span class="line">    </span><br><span class="line">    # 将对应的 icon 复制到需要修改的 app 的目录下</span><br><span class="line">    # .xcarchive 文件下对应的Applications文件路径</span><br><span class="line">    Applications_Path=$&#123;buildDir&#125;/Products/Applications</span><br><span class="line">    cp -Rf <span class="string">`<span class="subst">$&#123;iconPath&#125;</span>/<span class="subst">$&#123;appIcon&#125;</span>/*`</span> <span class="string">`$Applications_Path/*.app`</span></span><br><span class="line">    </span><br><span class="line">    <span class="keyword">if</span> [[ $? = <span class="number">0</span> ]]; then</span><br><span class="line">    echo <span class="string">"33[31m 修改 icon 成功33[0m"</span></span><br><span class="line">    <span class="keyword">else</span></span><br><span class="line">    echo <span class="string">"33[31m 修改 icon 失败33[0m"</span></span><br><span class="line">    fi</span><br><span class="line">    # 修改 Plist</span><br><span class="line">    # plist路径</span><br><span class="line">    infoPlist_File_Path=<span class="string">`$Applications_Path/*.app/info.plist`</span></span><br><span class="line"></span><br><span class="line">    /usr/libexec/PlistBuddy -c <span class="string">"Set :CFBundleName  $displayName"</span> $infoPlist_File_Path</span><br><span class="line">    /usr/libexec/PlistBuddy -c <span class="string">"Set :CFBundleDisplayName  $displayName"</span> $infoPlist_File_Path</span><br><span class="line">    /usr/libexec/PlistBuddy -c <span class="string">"Set :CFBundleIdentifier  $bundleIdentifier"</span> $infoPlist_File_Path</span><br><span class="line">    /usr/libexec/PlistBuddy -c <span class="string">"Set :ChannelCode  $channelCode"</span> $infoPlist_File_Path</span><br><span class="line">    /usr/libexec/PlistBuddy -c <span class="string">"Set :HostNumber  $hostNumber"</span> $infoPlist_File_Path         </span><br><span class="line">    /usr/libexec/PlistBuddy -c <span class="string">"Set :CFBundleShortVersionString  $version"</span> $infoPlist_File_Path</span><br><span class="line">    /usr/libexec/PlistBuddy -c <span class="string">"Set :HostUrl  $hostUrl"</span> $infoPlist_File_Path</span><br><span class="line">    </span><br><span class="line">    <span class="keyword">if</span> [[ $? = <span class="number">0</span> ]]; then</span><br><span class="line">    echo <span class="string">"33[31m 修改 Plist 成功33[0m"</span></span><br><span class="line">    <span class="keyword">else</span></span><br><span class="line">    echo <span class="string">"33[31m 修改 Plist 失败33[0m"</span></span><br><span class="line">    fi</span><br><span class="line"></span><br><span class="line">    # 重签名</span><br><span class="line">    #codesign -f -s "iPhone Distribution: Beijing Waming Environmental Technology Co., Ltd"  --entitlements $exportOptionsPlistPath $&#123;ipaPath&#125;/Payload/$&#123;schemeName&#125;.app</span><br><span class="line">    #if [[ $? = 0 ]]; then</span><br><span class="line">    #echo " 签名成功n "</span><br><span class="line">    #else</span><br><span class="line">    #echo " 签名失败n "</span><br><span class="line">    #fi</span><br><span class="line">    </span><br><span class="line">    # 生成 ipa</span><br><span class="line">    xcodebuild -exportArchive -archivePath $&#123;ipaPath&#125;/build/$&#123;schemeName&#125;.xcarchive -exportOptionsPlist $&#123;exportOptionsPlistPath&#125; -exportPath $&#123;ipaPath&#125;/$&#123;displayName&#125; -allowProvisioningUpdates $&#123;YES&#125; -allowProvisioningDeviceRegistration $&#123;YES&#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">if</span> [[ $? = <span class="number">0</span> ]]; then</span><br><span class="line">    echo <span class="string">"33[31m n 生成 IPA 成功 nnnnn33[0m"</span></span><br><span class="line">    <span class="keyword">else</span></span><br><span class="line">    echo <span class="string">"33[31m n 生成 IPA 失败 nnnnn33[0m"</span></span><br><span class="line">    fi</span><br><span class="line"></span><br><span class="line">    rm -rf $&#123;ipaPath&#125;/$&#123;displayName&#125;/$&#123;projectName&#125;.xcarchive</span><br><span class="line">    </span><br><span class="line">    # 上传fir</span><br><span class="line">    <span class="keyword">if</span> [[ $isUploadFir = <span class="number">1</span> ]]; then</span><br><span class="line">    echo <span class="string">"正在上传fir..."</span></span><br><span class="line">        fir p <span class="string">"$&#123;ipaPath&#125;/$&#123;displayName&#125;/$&#123;displayName&#125;.ipa"</span> -T $&#123;FirApiToken&#125;</span><br><span class="line">    fi</span><br><span class="line">    # 移动</span><br><span class="line">    #mv $&#123;ipaPath&#125;/$displayName/$displayName.ipa $&#123;allIPAPackPath&#125;/$appName</span><br><span class="line"></span><br><span class="line">    # 上传蒲公英分发平台</span><br><span class="line">    <span class="keyword">if</span> [[ $ISUPLOAD = <span class="number">1</span> ]]; then</span><br><span class="line">    echo <span class="string">"正在上传蒲公英..."</span></span><br><span class="line">    curl -F <span class="string">"file=@$ipaPath/$displayName/$displayName.ipa"</span> -F <span class="string">"uKey=$USERKEY"</span> -F <span class="string">"_api_key=$APIKEY"</span> http:<span class="comment">//www.pgyer.com/apiv1/app/upload</span></span><br><span class="line"></span><br><span class="line">    fi</span><br><span class="line">done</span><br><span class="line"></span><br><span class="line"># 结束时间</span><br><span class="line">endTime=<span class="string">`date +%s`</span></span><br><span class="line">echo -e <span class="string">"打包时间$[ endTime - beginTime ]秒"</span></span><br></pre></td></tr></table></figure>

<p> 判读用户是否有输入 1、AdHoc 2、AppStore 3、Enterprise 4、Development</p>
<blockquote>
<p>如果打包出现证书匹配问题，如果选择的auto 脚本里需要配置 ，上面脚本已经配置。</p>
<p> -allowProvisioningUpdates ${YES}</p>
<p> -allowProvisioningDeviceRegistration ${YES}</p>
</blockquote>
<blockquote>
<p>如果打包报其他错误，请先在Xcode项目上保证能archive，先解决掉代码上的错误才能保证脚本打包。</p>
</blockquote>
<p>等待生成ipa其中这儿生成替换的参数在APP中会读取，这儿也可以根据自己项目需求自定参数到info.plist下，然后在项目代码里实际的功能需求来操作。</p>
<ul>
<li>参数说明</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line">#app名字</span><br><span class="line">displayNameArr=(</span><br><span class="line">    <span class="string">"渝钱宝管家"</span></span><br><span class="line">    <span class="string">"开益宝助手"</span></span><br><span class="line">)</span><br><span class="line">#app的bundleId</span><br><span class="line">bundleIdentifierArr=(</span><br><span class="line">    <span class="string">"com.qyf.qyf"</span></span><br><span class="line">    <span class="string">"com.qyf.qyf"</span></span><br><span class="line">)</span><br><span class="line">#获取URL链接的主机地址编号</span><br><span class="line">hostNumberArr=(</span><br><span class="line">    <span class="string">"A022"</span></span><br><span class="line">    <span class="string">"A021"</span></span><br><span class="line">)</span><br><span class="line">#修改app文件地址</span><br><span class="line">appIconArr=(</span><br><span class="line">    <span class="string">"yqb_AppIcon"</span></span><br><span class="line">    <span class="string">"lebzs_AppIcon"</span></span><br><span class="line">)</span><br><span class="line">#打包渠道号</span><br><span class="line">channelCodeArr=(</span><br><span class="line">    <span class="string">"112"</span></span><br><span class="line">    <span class="string">"115"</span></span><br><span class="line">)</span><br></pre></td></tr></table></figure>



<p>这儿举个简单的例子例如hostNumberArr参数，在实际项目中是为了请求URL服务器地址的，然后在项目里获取到info.plist文件读取出来过后，然后在去请求服务器请求地址代码如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;&#x2F;获取开关配置和切换IP地址数据</span><br><span class="line">+(void)updateHostUrlSysCnfBlock:(void(^)(void))block&#123;</span><br><span class="line">    AFHTTPSessionManager *manger &#x3D;[AFHTTPSessionManager manager];</span><br><span class="line">    [manger.requestSerializer willChangeValueForKey:@&quot;timeoutInterval&quot;];</span><br><span class="line">    manger.requestSerializer.timeoutInterval &#x3D; 20.f;</span><br><span class="line">    [manger.requestSerializer didChangeValueForKey:@&quot;timeoutInterval&quot;];</span><br><span class="line">    NSString *hostNumber &#x3D; [NSBundle mainBundle].infoDictionary[@&quot;HostNumber&quot;];</span><br><span class="line">    NSString *getURL &#x3D; [NSString stringWithFormat:@&quot;http:&#x2F;&#x2F;sys.xxxx.cn:10271&#x2F;geturl?v&#x3D;%@&quot;,hostNumber];</span><br><span class="line">    [manger GET:getURL parameters:nil headers:nil progress:^(NSProgress *downloadProgress) &#123;</span><br><span class="line">    &#125; success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) &#123;</span><br><span class="line">        NSDictionary *info &#x3D; (NSDictionary *)responseObject;</span><br><span class="line">        if (info) &#123;</span><br><span class="line">            DataInstance.hideFlag &#x3D; ((NSString *)info[@&quot;hideFlag&quot;]).integerValue;</span><br><span class="line">            NSString *hostUrl &#x3D; info[@&quot;url&quot;];</span><br><span class="line">            if(![AppUtils isEmptyStr:hostUrl])&#123;</span><br><span class="line">                hostUrl &#x3D;[NSString stringWithFormat:@&quot;%@&#x2F;&quot;,info[@&quot;url&quot;]];</span><br><span class="line">                if (![DataInstance.hostUrl isEqualToString:hostUrl]) &#123;</span><br><span class="line">                    #ifdef DEBUG</span><br><span class="line">                    #else</span><br><span class="line">                        DataInstance.hostUrl &#x3D; hostUrl;</span><br><span class="line">                        [UserMgn cleanUser];</span><br><span class="line">                    #endif</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        &#x2F;&#x2F;进入控制器</span><br><span class="line">        if (block) &#123;block();&#125;</span><br><span class="line">    &#125; failure:^(NSURLSessionDataTask *task, NSError *error) &#123;</span><br><span class="line">        NSLog(@&quot;%@&quot;,error.localizedDescription);</span><br><span class="line">        if (block) &#123;block();&#125;</span><br><span class="line">    &#125;];</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p><strong>三、生成IPAS产品系列包</strong></p>
<ul>
<li>打包生成所有产品下的包</li>
</ul>
<p><a href="https://imgse.com/i/pp9qYTS" target="_blank" rel="noopener"><img src="https://s1.ax1x.com/2023/02/27/pp9qYTS.png" alt="pp9qYTS.png"></a></p>
<ul>
<li>如果需要上传fir平台</li>
</ul>
<p>如果没有安装fir插件，请先安装</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo gem install fir-cli –no-ri –no-rdoc</span><br></pre></td></tr></table></figure>
<p>执行成功会生成对应的项目文件目录</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">echo <span class="string">"fir平台..."</span></span><br><span class="line">fir p <span class="string">"$&#123;ipaPath&#125;/$&#123;displayName&#125;/$&#123;displayName&#125;.ipa"</span> -T <span class="number">931</span>b41960f7496b946ei2s13c910pdb97</span><br></pre></td></tr></table></figure>

<p>上面-T后面的token需要替换成你自己，上面只是例子随便的值，如果想要知道如果获取fir的token登陆fir官网看以下图<br><a href="https://imgse.com/i/pp9q2Y4" target="_blank" rel="noopener"><img src="https://s1.ax1x.com/2023/02/27/pp9q2Y4.png" alt="pp9q2Y4.png"></a></p>
<ul>
<li>如果需要上传蒲公英pgyer分发平台</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">echo <span class="string">"正在上传蒲公英..."</span></span><br><span class="line">curl -F <span class="string">"file=@$ipaPath/$displayName/$displayName.ipa"</span> -F <span class="string">"uKey=$USERKEY"</span> -F <span class="string">"_api_key=$APIKEY"</span> http:<span class="comment">//www.pgyer.com/apiv1/app/upload</span></span><br></pre></td></tr></table></figure>

<p>方法不累述 USERKEY和APIKEY，上面默认的脚本不上传fir和pgyer，你可以根据自己需求，打开注释，和修改是否需要上传蒲公英的状态开关。</p>
<p><a href="https://imgse.com/i/pp9Lp0f" target="_blank" rel="noopener"><img src="https://s1.ax1x.com/2023/02/27/pp9Lp0f.png" alt="pp9Lp0f.png"></a></p>
<p>如果上传fri,对应的二维码就是生成在fir平台的安装包</p>

      
    </div>
    <footer class="article-footer">
      
        <a data-url="https://kziwws.github.io/2023/01/21/technology20230121151206/" data-id="cmhm05vy2007jp4jjhw2sc7ch" class="article-share-link" data-share="baidu" data-title="IOS项目脚本自动化批量打包并上传第三方平台">分享到</a>
      

    
  <a href="https://kziwws.github.io/2023/01/21/technology20230121151206/#valine_thread" class="article-comment-link">评论</a>


      
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/ios/" rel="tag">ios</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/technology/" rel="tag">technology</a></li></ul>

    </footer>
  </div>
  
    <!-- 
<nav id="article-nav">
  
    <a href="/2023/02/10/technology20230210090112/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">下一篇</strong>
      <div class="article-nav-title">
        
          利用jekenis自动打包上传阿里云下载和通知钉钉机器人
        
      </div>
    </a>
  
  
    <a href="/2023/01/20/technology20230120161001/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">上一篇</strong>
      <div class="article-nav-title">IOS项目单独脚本自动化打包</div>
    </a>
  
</nav>
  -->








<nav id="article-nav">
  
    <a href="/2023/02/10/technology20230210090112/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption"><font size="2" color="#708090">下一篇 newer</font></strong>
      <div class="article-nav-title">
        
          <font color="#555">利用jekenis自动打包上传阿里云下载和通知钉钉机器人</font>
        
      </div>
    </a>
  
  
    <a href="/2023/01/20/technology20230120161001/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption"><font size="2" color="#708090">上一篇 older</font></strong>
      <div class="article-nav-title"><font color="#555">IOS项目单独脚本自动化打包</font></div>
    </a>
   
</nav>


  
</article>

  <section id="comments">
    <div id="valine_thread">
      <div class="comment"></div>
    </div>
  </section>
</section>
      
      <aside id="sidebar">
  
    
<div class="widget-wrap">
  <h3 class="widget-title">关于</h3>
  <ul class="widget about-me">
    
    <li><img class="author" title="About me" src="/img/github.png" /></li>
    
    
    <li ><font color="#424242" size="2em">苹果应用软件开发 & 游戏软件开发</font></li>
    
    <li ><font color="#424242" size="2em">email: ggb.chen@foxmail.com</font></li>
    
  </ul>
</div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">分类</h3>
    <div class="widget">
      <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/categories/charles/">charles</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/cocoapods/">cocoapods</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/cocosCreator/">cocosCreator</a><span class="category-list-count">8</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/error/">error</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/flutter/">flutter</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/git/">git</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/hexo/">hexo</a><span class="category-list-count">5</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/ios/">ios</a><span class="category-list-count">4</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/knowledge/">knowledge</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/python/">python</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/regexp/">regexp</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E8%AF%97/">诗</a><span class="category-list-count">46</span><ul class="category-list-child"><li class="category-list-item"><a class="category-list-link" href="/categories/%E8%AF%97/%E8%AF%97%E6%AD%8C/">诗歌</a><span class="category-list-count">9</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E8%AF%97/%E8%AF%97%E8%AF%8D/">诗词</a><span class="category-list-count">23</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E8%AF%97/%E8%BD%AC%E5%BD%95/">转录</a><span class="category-list-count">1</span></li></ul></li></ul>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">标签</h3>
    <div class="widget">
      <ul class="tag-list" itemprop="keywords"><li class="tag-list-item"><a class="tag-list-link" href="/tags/android/" rel="tag">android</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/cocoapods/" rel="tag">cocoapods</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/cocosCreator/" rel="tag">cocosCreator</a><span class="tag-list-count">8</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/flutter/" rel="tag">flutter</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/git/" rel="tag">git</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/hexo/" rel="tag">hexo</a><span class="tag-list-count">6</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/ios/" rel="tag">ios</a><span class="tag-list-count">4</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/knowledge/" rel="tag">knowledge</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/mac/" rel="tag">mac</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/poetry/" rel="tag">poetry</a><span class="tag-list-count">46</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/python/" rel="tag">python</a><span class="tag-list-count">4</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/regexp/" rel="tag">regexp</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/technology/" rel="tag">technology</a><span class="tag-list-count">29</span></li></ul>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">标签云</h3>
    <div class="widget tagcloud">
      <a href="/tags/android/" style="font-size: 11.67px;">android</a> <a href="/tags/cocoapods/" style="font-size: 10px;">cocoapods</a> <a href="/tags/cocosCreator/" style="font-size: 16.67px;">cocosCreator</a> <a href="/tags/flutter/" style="font-size: 11.67px;">flutter</a> <a href="/tags/git/" style="font-size: 10px;">git</a> <a href="/tags/hexo/" style="font-size: 15px;">hexo</a> <a href="/tags/ios/" style="font-size: 13.33px;">ios</a> <a href="/tags/knowledge/" style="font-size: 10px;">knowledge</a> <a href="/tags/mac/" style="font-size: 10px;">mac</a> <a href="/tags/poetry/" style="font-size: 20px;">poetry</a> <a href="/tags/python/" style="font-size: 13.33px;">python</a> <a href="/tags/regexp/" style="font-size: 10px;">regexp</a> <a href="/tags/technology/" style="font-size: 18.33px;">technology</a>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">归档</h3>
    <div class="widget">
      <!--<ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2025/11/">十一月 2025</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2023/09/">九月 2023</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2023/03/">三月 2023</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2023/02/">二月 2023</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2023/01/">一月 2023</a><span class="archive-list-count">3</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2022/10/">十月 2022</a><span class="archive-list-count">3</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2022/09/">九月 2022</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2022/01/">一月 2022</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2021/12/">十二月 2021</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2021/10/">十月 2021</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2021/08/">八月 2021</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2020/11/">十一月 2020</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2020/05/">五月 2020</a><span class="archive-list-count">3</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2020/04/">四月 2020</a><span class="archive-list-count">4</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2020/03/">三月 2020</a><span class="archive-list-count">15</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2020/02/">二月 2020</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2020/01/">一月 2020</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/12/">十二月 2019</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/10/">十月 2019</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/09/">九月 2019</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/08/">八月 2019</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/07/">七月 2019</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/06/">六月 2019</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/05/">五月 2019</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/03/">三月 2019</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/01/">一月 2019</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/12/">十二月 2018</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/11/">十一月 2018</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/08/">八月 2018</a><span class="archive-list-count">3</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/07/">七月 2018</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/06/">六月 2018</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/03/">三月 2018</a><span class="archive-list-count">3</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/02/">二月 2018</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/01/">一月 2018</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/06/">六月 2017</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/12/">十二月 2015</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/02/">二月 2015</a><span class="archive-list-count">5</span></li></ul> -->
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2025/11/">2025年</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2023/09/">2023年</a><span class="archive-list-count">6</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2022/10/">2022年</a><span class="archive-list-count">5</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2021/12/">2021年</a><span class="archive-list-count">3</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2020/11/">2020年</a><span class="archive-list-count">26</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/12/">2019年</a><span class="archive-list-count">13</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/12/">2018年</a><span class="archive-list-count">14</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/06/">2017年</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/12/">2015年</a><span class="archive-list-count">6</span></li></ul>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">近期文章</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/2025/11/05/technology20251105090825/">Sudoku Game Privacy Policy_ Zero Personal Data Collection, Pure Gaming Experience</a>
          </li>
        
          <li>
            <a href="/2023/09/10/technology20230910111821/">Hexo博客部署常见问题及解决方案</a>
          </li>
        
          <li>
            <a href="/2023/03/14/technology20230314101225/">利用python脚本拆解游戏中的图集资源</a>
          </li>
        
          <li>
            <a href="/2023/02/10/technology20230210090112/">利用jekenis自动打包上传阿里云下载和通知钉钉机器人</a>
          </li>
        
          <li>
            <a href="/2023/01/21/technology20230121151206/">IOS项目脚本自动化批量打包并上传第三方平台</a>
          </li>
        
      </ul>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">友情链接</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="https://github.com/kziwws" target="_blank">github</a>
          </li>
        
          <li>
            <a href="https://shevakuilin.com" target="_blank">shevakuilin</a>
          </li>
        
          <li>
            <a href="https://hans2936.github.io" target="_blank">hans2936</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
      
    </div>
    <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      &copy; 2015 <a href="https://github.com/kziwws" target="_blank">kziwws</a> 
      Powered by hexo,Theme by landscape-plus.
    </div>
    <div id="footer-info" class="inner">
      本站博客采用 <a href="http://creativecommons.org/licenses/by-nc-sa/3.0/cn/" target="_blank">[知识共享署名-非商业性使用-相同方式共享 3.0 中国大陆许可协议]</a> 进行许可
    </div>
  </div>
</footer>


<!--
<div id="footer-info" class="inner">
     &copy; 2025 kziwws<br>
      Powered by <a href="//hexo.io/" target="_blank">Hexo</a>
     .
     Theme by <a href="https://github.com/xiangming/landscape-plus" target="_blank">Landscape-plus</a>
   </div>
</div>
-->
  </div>
  <nav id="mobile-nav">
  
    <a href="/" class="mobile-nav-link">首页</a>
  
    <a href="/tags/technology" class="mobile-nav-link">编程技术</a>
  
    <a href="/tags/poetry" class="mobile-nav-link">诗</a>
  
    <a href="/tags/life" class="mobile-nav-link">生活随笔</a>
  
    <a href="/archives" class="mobile-nav-link">所有文章</a>
  
</nav>
  <!-- totop start -->
<div id="totop">
<a title="返回顶部"><img src="/img/scrollup.png"/></a>
</div>

<!-- totop end -->

<!--载入js，在</body>之前插入即可-->
    <!--Leancloud 操作库:-->
    <script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
    <!--Valine 的核心代码库-->
    <script src="/js/Valine.min.js"></script>
    <script>
        new Valine({
            av: AV, 
            el: '.comment',
            app_id: 'zh2N00Qk2UIsu1N8Qfu468TH-gzGzoHsz',
            app_key: 'BJrjTSEoKMfc05OMLWhCzmHk',
            placeholder: '想说点什么...',
            pageSize: 15,
            notify: false,
            verify: false,
        });
    </script>


<!-- 百度分享 start -->

<div id="article-share-box" class="article-share-box">
  <div id="bdshare" class="bdsharebuttonbox article-share-links">
    <a class="article-share-weibo" data-cmd="tsina" title="分享到新浪微博"></a>
    <a class="article-share-weixin" data-cmd="weixin" title="分享到微信"></a>
    <a class="article-share-qq" data-cmd="sqq" title="分享到QQ"></a>
    <a class="article-share-renren" data-cmd="renren" title="分享到人人网"></a>
    <a class="article-share-more" data-cmd="more" title="更多"></a>
  </div>
</div>
<script>
  function SetShareData(cmd, config) {
    if (shareDataTitle && shareDataUrl) {
      config.bdText = shareDataTitle;
      config.bdUrl = shareDataUrl;
    }
    return config;
  }
  window._bd_share_config={
    "common":{onBeforeClick: SetShareData},
    "share":{"bdCustomStyle":"/css/bdshare.css"}
  };
  with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='//bdimg.share.baidu.com/static/api/js/share.js?cdnversion='+~(-new Date()/36e5)];
</script>

<!-- 百度分享 end -->

<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>


  
<link rel="stylesheet" href="/fancybox/jquery.fancybox.css">

  
<script src="/fancybox/jquery.fancybox.pack.js"></script>




<! -- mathjax config similar to math.stackexchange -->

<script type="text/x-mathjax-config">
MathJax.Hub.Config({
tex2jax: {
          inlineMath: [ ['$','$'], ["\\(","\\)"]  ],
                processEscapes: true
                    
}
  
        });
</script>

<script type="text/x-mathjax-config">
MathJax.Hub.Config({
tex2jax: {
            skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
                  
}
    
        });
</script>

<script type="text/x-mathjax-config">
MathJax.Hub.Queue(function() {
            var all = MathJax.Hub.getAllJax(), i;
            for(i=0; i < all.length; i += 1) {
                            all[i].SourceElement().parentNode.className += ' has-jax';
                                    
            }
                
        });
</script>

<script type="text/javascript" src="//cdn.bootcss.com/mathjax/2.5.3/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>



<script src="/js/script.js"></script>


</div>

  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="icon-search"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.local-search-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url);
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content
                  
                  var upperBound = parseInt('-1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><span id="icon-search"></span></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><span id="icon-frown"></span></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }
          
          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script>
</body>
</html>

